/**
 * Author:	David Nguyen / Jack Hartwell
 * Course: 	44 543 Mobil Computing (Android)
 * Date: 	Mar 9, 2013
 *
 * Description: 
 */
package notecard_classes;

import java.util.ArrayList;

import android.util.Log;

/**
 * @author S511630
 *
 */
public class StudyCollectionFile {
	private ArrayList<Notecard> notecardCollection;
	private String fileName;
	private int countOfNotecards;
	
	public StudyCollectionFile(){
		this.notecardCollection = new ArrayList<Notecard>();
		this.fileName = new String();
		this.countOfNotecards = 0;
	}
	
	public void setFileName(String fileName){
		this.fileName = fileName;
	}
	
	public ArrayList<Notecard> getCollection(){
		return this.notecardCollection;
	}
	
	public Notecard getNotecard(int index){
		return this.notecardCollection.get(index);
	}
	
	public String getFileName(){
		return this.fileName;
	}
	
	public int getNotecardCount(){
		return this.countOfNotecards;
	}
	
	public void addNotecard(Notecard addToList){
		this.notecardCollection.add(addToList);
		this.countOfNotecards++;
	}
	
	public void addNotecard(String term, String definition){
		this.notecardCollection.add(new Notecard(term, definition));
		this.countOfNotecards++;
	}
	
	public void removeNotecard(Notecard thisCard){
		this.notecardCollection.remove(thisCard);
		this.countOfNotecards--;
	}
	
	public void removeNotecard(String lookForString, boolean byTerm){
		try{
			if(byTerm){
				this.notecardCollection.remove(findNotecardByTerm(lookForString));
			}else{
	
				this.notecardCollection.remove(findNotecardByDefinition(lookForString));
			}
			this.countOfNotecards--;
		}catch(ArrayIndexOutOfBoundsException outOfBounds){
			Log.w("File could not be found: ", outOfBounds);			
		}
	}
	
	private int findNotecardByTerm(String term){
		for(int indexLoc = 0; indexLoc < this.countOfNotecards; indexLoc++){
			if(this.notecardCollection.get(indexLoc).getTerm().equals(term)){
				return indexLoc;
			}
		}
		return -1;
	}
	
	private int findNotecardByDefinition(String definition){
		for(int indexLoc = 0; indexLoc < this.countOfNotecards; indexLoc++){
			if(this.notecardCollection.get(indexLoc).getDefinition().equals(definition)){
				return indexLoc;
			}
		}
		return -1;
	}

	public void readDoc(){
		
	}
	
	public void writeFile(){
		
	}
}
